/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmTransyHotel.java
 *
 * Created on 19-feb-2011, 11:14:36
 */

package Presentacion;

/**
 *
 * @author edu
 */
public class frmTransyHotel extends javax.swing.JFrame {

    /** Creates new form frmTransyHotel */
    int numCiudad;
    public frmTransyHotel(int indice) {
        initComponents();
        numCiudad=indice;
        listHoteles.setListData(frmPrincipal.agencia.Ciudades.get(indice).Hoteles.toArray());
        listTransportes.setListData(frmPrincipal.agencia.Ciudades.get(indice).Transportes.toArray());
        setTitle("ManchaViajes: Hoteles");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlPestañas = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        listHoteles = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        listTransportes = new javax.swing.JList();
        btnNuevo = new javax.swing.JButton();
        btnEditar = new javax.swing.JButton();
        btnCerrar = new javax.swing.JButton();
        btnBorrar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        pnlPestañas.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                pnlPestañasStateChanged(evt);
            }
        });

        listHoteles.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(listHoteles);

        pnlPestañas.addTab("Hoteles", jScrollPane1);

        listTransportes.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(listTransportes);

        pnlPestañas.addTab("Transportes", jScrollPane2);

        btnNuevo.setText("Nuevo");
        btnNuevo.setToolTipText("Nuevo Hotel");
        btnNuevo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnNuevoMouseClicked(evt);
            }
        });

        btnEditar.setText("Editar");
        btnEditar.setToolTipText("Editar Hotel");
        btnEditar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnEditarMouseClicked(evt);
            }
        });

        btnCerrar.setText("Cerrar");
        btnCerrar.setToolTipText("Cerrar");
        btnCerrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCerrarMouseClicked(evt);
            }
        });

        btnBorrar.setText("Borrar");
        btnBorrar.setToolTipText("Borrar Hotel");
        btnBorrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnBorrarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlPestañas, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnNuevo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnEditar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBorrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE)
                        .addComponent(btnCerrar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlPestañas, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnNuevo)
                    .addComponent(btnEditar)
                    .addComponent(btnCerrar)
                    .addComponent(btnBorrar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnNuevoMouseClicked
        if(pnlPestañas.getSelectedIndex()==0)
        {
            frmCrearHotel h = new frmCrearHotel(numCiudad);
            h.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            h.setVisible(true);
        }
        else
        {
            frmCrearTransporte t = new frmCrearTransporte(numCiudad);
            t.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            t.setVisible(true);
        }
    }//GEN-LAST:event_btnNuevoMouseClicked

    private void btnEditarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnEditarMouseClicked
        try{
            if(pnlPestañas.getSelectedIndex()==0)
            {
                frmEditarHotel ed = new frmEditarHotel(numCiudad, listHoteles.getSelectedIndex());
                ed.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                ed.setVisible(true);
            }else{
                frmEditarTransporte de = new frmEditarTransporte(numCiudad, listTransportes.getSelectedIndex());
                de.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                de.setVisible(true);
            }
        }catch(Exception e){}
    }//GEN-LAST:event_btnEditarMouseClicked

    private void btnCerrarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCerrarMouseClicked
        setVisible(false);
    }//GEN-LAST:event_btnCerrarMouseClicked

    private void pnlPestañasStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_pnlPestañasStateChanged
        if(pnlPestañas.getSelectedIndex()==0)
        {
            setTitle("ManchaViajes: Hoteles");
            btnBorrar.setToolTipText("Borrar Hotel");
            btnEditar.setToolTipText("Editar Hotel");
            btnNuevo.setToolTipText("Nuevo Hotel");
        }
        else
        {
            setTitle("ManchaViajes: Transportes");
            btnBorrar.setToolTipText("Borrar Transporte");
            btnEditar.setToolTipText("Editar Transporte");
            btnNuevo.setToolTipText("Nuevo Transporte");
        }
    }//GEN-LAST:event_pnlPestañasStateChanged

    private void btnBorrarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBorrarMouseClicked
        try{
        if(pnlPestañas.getSelectedIndex()==0)
        {
            frmPrincipal.agencia.Ciudades.get(numCiudad).Hoteles.remove(listHoteles.getSelectedIndex());
            this.listHoteles.setListData(frmPrincipal.agencia.Ciudades.get(numCiudad).Hoteles.toArray());

        }
        else
        {
            frmPrincipal.agencia.Ciudades.get(numCiudad).Transportes.remove(listTransportes.getSelectedIndex());
            listTransportes.setListData(frmPrincipal.agencia.Ciudades.get(numCiudad).Transportes.toArray());

        }
        }catch(Exception ex){}
    }//GEN-LAST:event_btnBorrarMouseClicked

    /**
    * @param args the command line arguments
    */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmTransyHotel(0).setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBorrar;
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    public static javax.swing.JList listHoteles;
    public static javax.swing.JList listTransportes;
    private javax.swing.JTabbedPane pnlPestañas;
    // End of variables declaration//GEN-END:variables

}
